import {
  createApi,
  fetchBaseQuery,
} from './@reduxjs/toolkit/query/react'

const todosApi = createApi({
  reducerPath: 'todos', // reducer 处理函数的 key
  baseQuery: fetchBaseQuery({
    baseUrl: 'http://localhost:8080', // 网络请求的基础路径
  }),
  endpoints: (builder) => {
    return {
      getTodos: builder.query({ query: () => `/todos/list` }),
      getTodo: builder.query({
        query: (id) => {
          return `/todos/detail/${id}`
        }
      }),
    }
  }
})

export default todosApi
